package project.suntray.com.core.delegates;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import me.yokeyword.fragmentation.ExtraTransaction;
import me.yokeyword.fragmentation.ISupportFragment;
import me.yokeyword.fragmentation.SupportFragmentDelegate;
import me.yokeyword.fragmentation.anim.FragmentAnimator;

/**
 * Created by zhangyang on 2017/12/12 14:53.
 * version 1
 * notes 创建基础的delagate--其实就是一个fragment
 * butterknife 进行绑定 解绑抽象方法的创建
 */
public abstract class BaseDelagate extends Fragment implements ISupportFragment{

    Unbinder unbinder;
    /**
     * 设置布局
     * @return
     */
    public abstract  Object setLayout();

    /**
     * 进行底层的绑定数据
     * @param rootView
     * @param savedInstanceState
     */
    public abstract void bindView(View rootView,Bundle savedInstanceState);

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View rootView=null;
        if(setLayout()==null){
            throw new RuntimeException("layout is null");
        }else{
            if(setLayout() instanceof  Integer){
                rootView=inflater.inflate((Integer) setLayout(),container,false);
                unbinder= ButterKnife.bind(rootView,getActivity());
                bindView(rootView,savedInstanceState);
            }else if(setLayout() instanceof View){
                rootView=(View)setLayout();
                unbinder= ButterKnife.bind(rootView,getActivity());
                bindView(rootView,savedInstanceState);
            }else{
                throw new RuntimeException("layout is null");
            }
        }
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        /**
         * 最后的解除绑定
         */
        if(unbinder!=null){
            unbinder.unbind();
        }
    }

    @Override
    public SupportFragmentDelegate getSupportDelegate() {
        return null;
    }

    @Override
    public ExtraTransaction extraTransaction() {
        return null;
    }

    @Override
    public void enqueueAction(Runnable runnable) {

    }

    @Override
    public void onEnterAnimationEnd(@Nullable Bundle savedInstanceState) {

    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {

    }

    @Override
    public void onSupportVisible() {

    }

    @Override
    public void onSupportInvisible() {

    }

    @Override
    public boolean isSupportVisible() {
        return false;
    }

    @Override
    public FragmentAnimator onCreateFragmentAnimator() {
        return null;
    }

    @Override
    public FragmentAnimator getFragmentAnimator() {
        return null;
    }

    @Override
    public void setFragmentAnimator(FragmentAnimator fragmentAnimator) {

    }

    @Override
    public void setFragmentResult(int resultCode, Bundle bundle) {

    }

    @Override
    public void onFragmentResult(int requestCode, int resultCode, Bundle data) {

    }

    @Override
    public void onNewBundle(Bundle args) {

    }

    @Override
    public void putNewBundle(Bundle newBundle) {

    }

    @Override
    public boolean onBackPressedSupport() {
        return false;
    }
}
